package it.afs.worklog.application.form;

import java.util.List;

import it.afs.worklog.Cliente;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.IChoiceRenderer;
import org.apache.wicket.model.IModel;

public class ClienteDropDownChoice extends DropDownChoice<Cliente>
{
	private static final long serialVersionUID = 4955688956299005353L;
	
	private boolean showDisabled = false;

	public ClienteDropDownChoice(String id, IModel<? extends List<? extends Cliente>> choices)
	{
		super(id, choices);
	}

	public ClienteDropDownChoice(String id, IModel<Cliente> model, List<? extends Cliente> choices)
	{
		super(id, model, choices);
	}
	
	public ClienteDropDownChoice(String id, IModel<Cliente> model, IModel<? extends List<? extends Cliente>> choices) {
		super(id, model, choices);
	}

	@Override
	protected void onConfigure()
	{
		setChoiceRenderer(new ClienteChoiceRenderer());
		super.onConfigure();
	}
	
	@Override
	protected boolean isDisabled(Cliente object, int index, String selected)
	{
		return !object.getAttivo() && !showDisabled;
	}
	
	public boolean isShowDisabled() {
		return showDisabled;
	}

	public void setShowDisabled(boolean showDisabled) {
		this.showDisabled = showDisabled;
	}

	private class ClienteChoiceRenderer implements IChoiceRenderer<Cliente>
	{
		private static final long serialVersionUID = 5793328771062161265L;

		@Override
		public Object getDisplayValue(Cliente object)
		{
			return object.getNominativo();
		}

		@Override
		public String getIdValue(Cliente object, int index)
		{
			return String.valueOf(index);
		}
	}
}